﻿using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Service.IService.ProductionControl;

//创建时间：2025-01-21
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 夹具信息
    /// </summary>
    [Verify]
    [Route("business/CksFixtureinfo")]
    [ApiExplorerSettings(GroupName = "business")]
    public class CksFixtureinfoController : BaseController
    {
        /// <summary>
        /// 夹具信息接口
        /// </summary>
        private readonly ICksFixtureinfoService _CksFixtureinfoService;

        public CksFixtureinfoController(ICksFixtureinfoService CksFixtureinfoService)
        {
            _CksFixtureinfoService = CksFixtureinfoService;
        }

        /// <summary>
        /// 查询夹具信息列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "cksfixtureinfo:list")]
        public IActionResult QueryCksFixtureinfo([FromQuery] CksFixtureinfoQueryDto parm)
        {
            var response = _CksFixtureinfoService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询夹具信息详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "cksfixtureinfo:query")]
        public IActionResult GetCksFixtureinfo(int Id)
        {
            var response = _CksFixtureinfoService.GetInfo(Id);

            var info = response.Adapt<CksFixtureinfoDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加夹具信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "cksfixtureinfo:add")]
        [Log(Title = "夹具信息", BusinessType = BusinessType.INSERT)]
        public IActionResult AddCksFixtureinfo([FromBody] CksFixtureinfoDto parm)
        {
            var modal = parm.Adapt<CksFixtureinfo>().ToCreate(HttpContext);

            var response = _CksFixtureinfoService.AddCksFixtureinfo(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新夹具信息
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "cksfixtureinfo:edit")]
        [Log(Title = "夹具信息", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateCksFixtureinfo([FromBody] CksFixtureinfoDto parm)
        {
            var modal = parm.Adapt<CksFixtureinfo>().ToUpdate(HttpContext);
            var response = _CksFixtureinfoService.UpdateCksFixtureinfo(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除夹具信息
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "cksfixtureinfo:delete")]
        [Log(Title = "夹具信息", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteCksFixtureinfo([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_CksFixtureinfoService.Delete(idArr));
        }

        /// <summary>
        /// 重置工装夹具信息
        /// </summary>
        /// <returns></returns>
        [HttpPut("reset/{ids}")]
        [ActionPermissionFilter(Permission = "cksfixtureinfo:edit")]
        [Log(Title = "工装夹具次数清零", BusinessType = BusinessType.UPDATE)]
        public IActionResult ResetCksFixtureinfo([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_CksFixtureinfoService.Reset(idArr));
        }
    }
}